import request from '@/utils/request'

const api_name = '/user'

export function login(data) {
  return request({
    url: `${api_name}/login`,
    method: 'post',
    data
  })
}

export function getInfo(token) {
  return request({
    url: `${api_name}/info`,
    method: 'get'
    // params: { token }
  })
}

export function getRouters() {
  return request({
    url: `/function/getRouters`,
    method: 'get'
  })
}

export function logout() {
  return request({
    url: `${api_name}/logout`,
    method: 'post'
  })
}

export default {
  userListPage(page, limit, searchObj) {
    return request({
      url: `${api_name}/list/${page}/${limit}`,
      method: 'get',
      params: searchObj
    })
  },
  findDeptList() {
    return request({
      url: `${api_name}/findDeptList`,
      method: 'get'
    })
  },
  findById(id) {
    return request({
      url: `${api_name}/findById/${id}`,
      method: 'get'
    })
  },
  addUser(user) {
    return request({
      url: `${api_name}/addUser`,
      method: 'post',
      data: user
    })
  },
  updateUser(user) {
    return request({
      url: `${api_name}/updateUser`,
      method: 'put',
      data: user
    })
  },
  delUser(userId) {
    return request({
      url: `${api_name}/delete/${userId}`,
      method: 'delete'
    })
  },
  changeUserStatus(userId, status) {
    return request({
      url: `${api_name}/changeUserStatus/${userId}/${status}`,
      method: 'get'
    })
  },
  logout() {
    return request({
      url: `${api_name}/logout`,
      method: 'get'
    })
  },
  checkIsLoginNameExist(name) {
    return request({
      url: `${api_name}/checkIsLoginNameExist`,
      method: 'get',
      params: name
    })
  },
  checkIsUserNameExist(name) {
    return request({
      url: `${api_name}/checkIsUserNameExist`,
      method: 'get',
      params: name
    })
  },
  selectRole(data) {
    return request({
      url: `${api_name}/selectRole`,
      method: 'post',
      data: data
    })
  },
  resetPwd(id) {
    return request({
      url: `${api_name}/resetPwd/${id}`,
      method: 'post'
    })
  },
  deleteBatch(ids) {
    return request({
      url: `${api_name}/deleteBatch`,
      method: 'delete',
      data: ids
    })
  },
  batchSetStatus(ids, status) {
    return request({
      url: `${api_name}/batchSetStatus/${status}`,
      method: 'post',
      data: ids
    })
  },
  // 删除角色
  deleteById(id) {
    return request({
      url: `${api_name}/delete/${id}`,
      method: 'delete'
    })
  }
}
